package com.iMusic.integrationLayer;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mysql.jdbc.Statement;


public class DBConnection_test extends HttpServlet {

	static String SERVER = "127.0.0.1";
	static String user = "client";
	static String passwd = "client1";
	static String database = "iMusicDB";
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Connection conn = null;
		String url = "jdbc:mysql://localhost/";
		String dbName = "iMusicDB";
		String driver = "com.mysql.jdbc.Driver";
		String userName = "client"; 
		String password = "client1";
		try {
			Class.forName(driver).newInstance();
			conn = DriverManager.getConnection(url+dbName,userName,password);
			System.err.println("Connected to the database");
			
			java.sql.Statement stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery("select * from category");
			
			while (rs.next()) {
				System.err.println(rs.getInt("category_id"));
				System.err.println(rs.getString("description"));
			}
			
			conn.close();
			System.err.println("Disconnected from database");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
        response.sendRedirect("http://www.google.com");

	}
	
	
}
